<?php

namespace app;

class BaseService
{
    //protected $result; //这里不能加，会有冲突

    /**
     * 供外部访问的信息
     * @var $message
     */
    public $message = "";

    /**
     * 供外部访问的错误码
     * @var $errorCode
     */
    public $errorCode;

    /**
     * @var $data
     */
    public $data;


    /**
     * @var null
     */
    private static $instanceMap = null;

    private $clientType;

    /**
     * 获取service的实例
     * @return static
     */
    public static function getInstance()
    {
        $class = get_called_class();
        if (!isset(self::$instanceMap[$class])) {
            $instance = new $class();
            self::$instanceMap[$class] = $instance;
            return $instance;
        }
        return self::$instanceMap[$class];
    }

    public function __construct()
    {
    }

    public function setClientType($clientType)
    {
        $this->clientType = $clientType;
    }

    public function getClientType()
    {
        if (empty($this->clientType)) {
            $this->clientType = 'pc';
        }
        return $this->clientType;
    }

}
